package com.efounder.frame.activity;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;

import com.efounder.frame.baseui.EFActivity;
import com.efounder.frame.manager.AppLoginManager;
import com.efounder.frame.manager.UrlSchemeManager;
import com.efounder.frame.utils.UrlSchemeFactory;
import com.efounder.util.ToastUtil;

/**
 * 处理urlscheme的 activity
 * Created by yqs
 * Date: 2019/10/17
 * Time: 11:04
 */
public class UrlSchemeFilterActivity extends EFActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        if (getIntent() == null) {
            finish();
        }

        //判断是否通过urlscheme调用
        Intent intent = getIntent();
        if (!UrlSchemeManager.hasUrlScheme(intent)) {
            ToastUtil.showToast(this, "只能通过url scheme 调用");
            finish();
            return;
        }
        //判断是否登录
        if (!AppLoginManager.isUserLogined()) {
            AppLoginManager.showNotLogInDialog(this);
            return;
        }
        UrlSchemeManager schemeManager = new UrlSchemeManager(intent);
        String type = schemeManager.getQueryValue(UrlSchemeFactory.getInstance().getSchemeTypeKey());
        if (TextUtils.isEmpty(type)) {
            ToastUtil.showToast(this, UrlSchemeFactory.getInstance().getSchemeTypeKey() + "参数不能为空");
            return;
        }

        UrlSchemeFactory.IScheme scheme = UrlSchemeFactory.getInstance().getScheme(type);
        if (scheme == null) {
            ToastUtil.showToast(this, "未找到注册的IScheme类");
            return;
        }
        //执行相应的处理
        scheme.doActioin(this, getIntent());


    }


    @Override
    protected void onResume() {
        super.onResume();
    }
}
